package com.example.service;

import cn.hutool.core.date.DateUtil;
import com.example.entity.Comment;
import com.example.entity.Params;

import com.example.mapper.CommentMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentService {
    @Autowired
    private CommentMapper commentMapper;


    public PageInfo<Comment> findBySearch(Params params) {
        PageHelper.startPage(params.getPageNum(), params.getPageSize());


        List<Comment> list = commentMapper.findBySearch(params);
        return PageInfo.of(list);
    }

    public void delete(Integer id) {

        commentMapper.deleteById(id);
    }


    public void addComment(Comment comment) {
        comment.setTime(DateUtil.now());
        commentMapper.add(comment);
    }
}
